package io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor;

import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.Visitable;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.visitor.Visitor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 对象结构
 * <p>
 * 构成元素可以是枚举、可以是集合、可以使用Composite组合模式、...
 *
 * @author yth
 * @since 2023-04-29-16:55
 */
public class ObjectStructure {

    private final List<Visitable> elements = new ArrayList<>();

    public void add(Visitable element) {
        elements.add(element);
    }

    public void addAll(Collection<Visitable> collection) {
        elements.addAll(collection);
    }

    public void remove(Visitable element) {
        elements.remove(element);
    }

    public void accept(Visitor visitor) {
        elements.forEach(e -> e.accept(visitor));
    }

}
